import Mock from 'mockjs'
import setupMock, {
    successResponseWrap,
    failResponseWrap,
} from '@/libs/setup-mock'

import '@/components/image-picker/mock'

// app列表
import appList from './data/appList.json'
// appJSON数据
import appJsonData from './data/appJsonData.json'

// 模板分类列表
import templateCategoryList from './data/templateCategoryList.json'
// 模板分类下的数据列表
import templateCategoryDatas from './data/templateCategoryDatas.json'
// 我的模板分类列表
import templateCategoryUserList from './data/templateCategoryUserList.json'
// 组件类的模板分类列表
import templateCategoryListById from './data/templateCategoryListById.json'
// 组件类分类下的数据列表
import templateCategoryDatasById from './data/templateCategoryDatasById.json'

// 用户角色列表
import userRoleList from './data/userRoleList.json'
// 表单列表
import objectList from './data/objectList.json'

// 获取app数据(阿里云链接)
// const getJsonOssUrl = 'https://faimg.waliapp.cn/apps%2Fbq2jof278lvdaisp29bg%2Fjsons%2Fci36mqcvpifovok3kvbg.json?Expires=1686792554&OSSAccessKeyId=LTAI5tCzY2sTzg5o1wd7ZWKi&Signature=n3jE9ANox31E1uxCXB21OHKamYA%3D'
const getJsonOssUrl = 'api/app/getJson'
// 保存app数据(阿里云链接)
const saveJsonOssUrl = 'api/app/saveJson'
// 获取我的模块数据(阿里云链接)
const getModuleSourceOssUrl = '/api/app/module/getModuleSourceJson'

setupMock({
    mock: true,
    setup() {
        // 获取app列表
        Mock.mock(new RegExp('api/app/getAppList'), () => {
            return appList
        })
        // 删除指定app
        Mock.mock(new RegExp('api/app/deleteApp'), () => {
            return {
                "Code": 0,
                "Data": null,
                "Message": "删除成功！",
                "Status": 1
            }
        })
        // 获取app数据
        Mock.mock(new RegExp('api/app/getApp'), () => {
            return {
                "Status": 1,
                "Message": "",
                "Data": {
                    "Id": "bq2jof278lvdaisp29bg",
                    "CreatedAt": "2020-04-02T09:13:32+08:00",
                    "UpdatedAt": "2023-06-12T08:48:41.625874+08:00",
                    "Version": "",
                    "MemberId": "binfbsc6no9k7p6m6ac0",
                    "Name": "瓦立应用",
                    "Code": "",
                    "CataJSON": "",
                    "DataJSON": "{\"modulePageConfigs\":{\"goodsDetail\":{\"router\":\"goodsDetail\",\"name\":\"商品详情\",\"customFeature\":{\"name\":\"商品详情\",\"theme\":{\"primaryColor\":\"#ec612a\",\"secondaryColor\":\"#f7c747\",\"tertiaryColor\":\"#ff6347\"},\"hiddenGoodsPrice\":false,\"hiddenGoodsOriginalPrice\":false,\"hiddenGoodsPurchaseType\":false,\"hiddenGoodsExpress\":false,\"hiddenGoodsSold\":false,\"hiddenGoodsDetails\":false,\"hiddenGoodsParams\":false,\"hiddenGoodsComment\":false,\"goodsBottomBtns\":[{\"label\":\"首页\",\"name\":\"home\"},{\"label\":\"购物车\",\"name\":\"shopCart\"},{\"label\":\"分享\",\"name\":\"share\"},{\"label\":\"客服\",\"name\":\"contact\"}]}},\"schedule\":{\"router\":\"schedule\",\"name\":\"预约\",\"customFeature\":{\"name\":\"预约\",\"theme\":{\"primaryColor\":\"#488FF7\",\"primaryFontColor\":\"#333\",\"secondaryFontColor\":\"#fff\"},\"displayDays\":7,\"displayOverdueItemMode\":2,\"displayBookedItemMode\":2}},\"questionIndex\":{\"router\":\"questionIndex\",\"name\":\"答题\",\"customFeature\":{\"name\":\"答题\",\"style\":{\"background-image\":\"https://res.waliapp.cn/apps/c55a38svpifpmpqt1kl0/cd2d3k4vpifumqu364q0/res/images/2022/10/cd7li2pj34q9vrd7n1l0.png\"},\"displayTitle\":true,\"titleText\":\"答题活动\",\"titleTheme\":{\"color\":\"#fff\",\"font-size\":\"14px\"},\"displayNameText\":true,\"nameText\":\"主办方:网络科技有限公司\",\"nameTheme\":{\"color\":\"#fff\",\"font-size\":\"12px\"},\"buttonList\":[{\"title\":\"活动规则\",\"style\":{\"color\":\"#fff\",\"font-size\":\"16px\",\"font-weight\":\"\",\"background-color\":\"#7AC0FF\"},\"pageCode\":\"rule\",\"isShow\":true},{\"title\":\"开始答题\",\"style\":{\"color\":\"#fff\",\"font-size\":\"16px\",\"font-weight\":\"\",\"background-color\":\"#7AC0FF\"},\"pageCode\":\"question\",\"isShow\":true},{\"title\":\"个人中心\",\"style\":{\"color\":\"#fff\",\"font-size\":\"16px\",\"font-weight\":\"\",\"background-color\":\"#7AC0FF\"},\"pageCode\":\"userCenter\",\"isShow\":true},{\"title\":\"满分榜单\",\"style\":{\"color\":\"#fff\",\"font-size\":\"16px\",\"font-weight\":\"\",\"background-color\":\"#7AC0FF\"},\"pageCode\":\"category\",\"isShow\":true}]}},\"questionAuthorization\":{\"router\":\"questionAuthorization\",\"name\":\"身份授权\",\"customFeature\":{\"name\":\"身份授权\",\"style\":{\"background-image\":\"https://res.waliapp.cn/apps/c55a38svpifpmpqt1kl0/cd2d3k4vpifumqu364q0/res/images/2022/10/cd7li2pj34q9vrd7n1l0.png\"},\"submitButton\":{\"style\":{\"background-color\":\"#CC0C08\",\"color\":\"#fff\"}},\"promptList\":[\"一是用于抽奖后发个人奖品。\",\"二是用于综合统计排名后，评出组织奖。\"]}},\"questionResult\":{\"router\":\"questionResult\",\"name\":\"答题结果\",\"customFeature\":{\"name\":\"答题结果\",\"style\":{\"background-image\":\"https://res.waliapp.cn/apps/c55a38svpifpmpqt1kl0/cd2d3k4vpifumqu364q0/res/images/2022/10/cd7li2pj34q9vrd7n1l0.png\"}}},\"questionAnswer\":{\"router\":\"questionAnswer\",\"name\":\"题目\",\"customFeature\":{\"name\":\"题目\",\"style\":{\"background-image\":\"https://res.waliapp.cn/apps/c55a38svpifpmpqt1kl0/cd2d3k4vpifumqu364q0/res/images/2022/10/cd7li2pj34q9vrd7n1l0.png\"},\"questionNumber\":{\"style\":{\"background-color\":\"#CC0C08\",\"color\":\"#fff\"}},\"submitButton\":{\"style\":{\"background-color\":\"#CC0C08\",\"color\":\"#fff\"}},\"radioButton\":{\"style\":{\"background-color\":\"#dccdb9\",\"color\":\"#7F633E\"}}}}}}",
                    "Type": "",
                    "Description": "",
                    "HistoryId": "ci36mqcvpifovok3kvbg",
                    // "OssGetUrl": "https://faimg.waliapp.cn/apps%2Fbq2jof278lvdaisp29bg%2Fjsons%2Fci36mqcvpifovok3kvbg.json?Expires=1686792554&OSSAccessKeyId=LTAI5tCzY2sTzg5o1wd7ZWKi&Signature=n3jE9ANox31E1uxCXB21OHKamYA%3D",
                    "OssGetUrl": getJsonOssUrl,
                    "TemplateId": "",
                    "NeedNewVersion": 0,
                    "TypeId": "c7b4hs60npqkbb5486d0",
                    "ExpiredAt": "",
                    "AvaterUrl": "",
                    "IsDynamicData": 0,
                    "AppVersion": 4,
                    "OrganizationId": "cg785h9j34qenrah67v0",
                    "VipCardStatus": 0,
                    "RechargeCardStatus": 0
                }
            }
        })
        // 获取app数据JSON
        Mock.mock(new RegExp(getJsonOssUrl), () => {
            return appJsonData
        })
        // 保存app数据
        Mock.mock(new RegExp('api/app/saveApp'), () => {
            return {
                "Status": 1,
                "Message": "保存成功！",
                "Data": {
                    "AppId": "cgrn31cvpifpd6ve50eg",
                    "HistoryId": "ci572esvpifovok3l14g",
                    "OssPutUrl": saveJsonOssUrl
                }
            }
        })
        // 保存app数据到阿里云
        Mock.mock(new RegExp(saveJsonOssUrl), () => {
            return true
        })

        // 获取组件类的模板分类列表 (自由面板、营销...)
        Mock.mock(new RegExp('/api/app/template/category/list/byId'), 'get', () => {
            return templateCategoryListById
        })
        // 获取模板分类列表 dynamic(动态分类)、industry(行业)、odule(组件)、cutPage(单页)
        Mock.mock(new RegExp('/api/app/template/category/list'), 'get', () => {
            return templateCategoryList
        })
        // 获取我的模板分类列表
        Mock.mock(new RegExp('/api/app/template/category/user/list'), 'get', () => {
            return templateCategoryUserList
        })
        // 删除我的模板分类
        Mock.mock(new RegExp('/api/app/template/category/user/delete/*'), 'delete', () => {
            return {
                "Code": 0,
                "Data": null,
                "Message": "删除成功！",
                "Status": 1
            }
        })
        // 获取组件类的模板数据 (自由面板、营销...)
        Mock.mock(new RegExp('/api/app/template/category'), 'get', () => {
            return templateCategoryDatasById
        })
        
        // 根据分类ID获取分类下全部模板数据 (自由面板、营销...)
        Mock.mock(new RegExp('/api/app/template/getCategoryAllTmplData'), 'get', () => {
            return templateCategoryDatas
        })

        // 添加为系统模板
        Mock.mock(new RegExp('/api/app/template/save/sysTemplate'), 'post', () => {
            return {
                "Code": 0,
                "Data": null,
                "Message": "操作成功！",
                "Status": 1
            }
        })

        // 获取我的模板数据
        Mock.mock(new RegExp('/api/app/template/user/list'), 'get', () => {
            return templateCategoryDatas
        })
        // 添加/修改我的模板分类
        Mock.mock(new RegExp('/api/app/template/user/category/save'), 'post', () => {
            return {
                "Code": 0,
                "Data": {
                    "Id": "ci5bassvpifovok3l1hg",
                    "CreatedAt": "2023-06-15T14:53:39.282237446+08:00",
                    "UpdatedAt": "2023-06-15T14:53:39.282237446+08:00",
                    "Version": "",
                    "Title": "分类名",
                    "Pid": "0",
                    "MemberId": "",
                    "AppId": "bq2jof278lvdaisp29bg"
                },
                "Message": "操作成功！",
                "Status": 1
            }
        })
        // 收藏模板
        Mock.mock(new RegExp('/api/app/template/user/save'), 'post', () => {
            return {
                "Code": 0,
                "Data": {
                    "Id": "ci5beo4vpifovok3l1i0",
                    "CreatedAt": "2023-06-15T15:01:52.250362447+08:00",
                    "UpdatedAt": "2023-06-15T15:01:52.248443867+08:00",
                    "Version": "",
                    "Title": "test",
                    "Cover": "",
                    "Sort": 1,
                    "Type": "comb",
                    "CategoryId": "c813md4vpifrqblirm00",
                    "Data": "{\"component\":{\"show\":true,\"title\":\"自由面板\",\"icon\":\"icon-widget-free-vessel\",\"type\":\"2\",\"helpHref\":\"https://www.yuque.com/zhonglixunni/wali/hcblq8\"},\"config\":true,\"eles\":{\"type\":\"free-vessel\",\"style\":{\"background-repeat\":\"no-repeat\",\"background-size\":\"100% 100%\",\"width\":\"320px\",\"height\":\"150px\",\"background-color\":\"rgba(255, 255, 255, 1)\",\"background-image\":\"\",\"box-shadow\":\"\",\"border-color\":\"#409EFF\",\"border-radius\":\"0px\",\"border-style\":\"none\",\"border-width\":\"2px\",\"margin-top\":\"0px\",\"margin-left\":\"0px\",\"margin-right\":\"auto\",\"opacity\":1},\"content\":[],\"customFeature\":{\"boxStyle\":false,\"boxColor\":\"rgb(0, 0, 0)\",\"boxR\":\"5\",\"boxX\":\"0\",\"boxY\":\"0\",\"name\":\"自由面板\",\"id\":\"wlKTYK9am61\"},\"animations\":[],\"hidden\":false,\"id\":\"wl4aROADksb\"}}",
                    "Description": "",
                    "Code": "",
                    "AppId": "bq2jof278lvdaisp29bg",
                    "MemberId": "binfbsc6no9k7p6m6ac0"
                },
                "Message": "操作成功！",
                "Status": 1
            }
        })
        // 删除我的模板
        Mock.mock(new RegExp('/api/app/template/user/remove/*'), 'delete', () => {
            return {
                "Code": 0,
                "Data": null,
                "Message": "删除成功！",
                "Status": 1
            }
        })

        // 获取用户角色列表
        Mock.mock(new RegExp('/api/app/user/role/list'), 'get', () => {
            return userRoleList
        })

        // 获取跳转小程序列表
        Mock.mock(new RegExp('/api/app/system/whitelist/list'), 'get', () => {
            return {
                "Code": 0,
                "Data": {
                    "total_record": 1,
                    "total_page": 1,
                    "offset": 0,
                    "limit": 10000,
                    "page": 1,
                    "prev_page": 1,
                    "next_page": 1,
                    "records": [
                        {
                            "Id": "c6er6tcvpifsn137rnh0",
                            "CreatedAt": "2021-11-24T11:37:25+08:00",
                            "UpdatedAt": "2021-11-24T11:37:25+08:00",
                            "Version": "",
                            "AppId": "bq2jof278lvdaisp29bg",
                            "TargetId": "wx--------------",
                            "TargetName": "瓦立应用小程序",
                            "TargetPagePath": "/pages/index/index",
                            "TargetPageName": "",
                            "Description": ""
                        }
                    ]
                },
                "Message": "获取成功",
                "Status": 1
            }
        })

        // 获取表单列表
        Mock.mock(new RegExp('/admin/obj/GetObjectList'), 'post', () => {
            return objectList
        })
        
        // 获取模板消息
        Mock.mock(new RegExp('/appAdmin/GetMessageTemplateList'), 'post', () => {
            return {
                "code": 200,
                "msg": "ok",
                "data": {
                    "total_record": 1,
                    "total_page": 1,
                    "offset": 0,
                    "limit": 9999,
                    "page": 1,
                    "prev_page": 1,
                    "next_page": 1,
                    "records": [
                        {
                            "id": "cb8d2lpj34qbct1fgm4g",
                            "title": "消息发送test",
                            "type": 2,
                            "template_id": "WtzPoyHDx2Yjs9uvyED0nWsHcheZ9Hby7Y0sONYoccs",
                            "template_title": "消息发送test",
                            "template_content": "[{\"key\": \"上报人\", \"value\": \"thing1\"}, {\"key\": \"上报时间\", \"value\": \"thing2\"}, {\"key\": \"案件位置\", \"value\": \"thing3\"}, {\"key\": \"案件内容\", \"value\": \"thing4\"}, {\"key\": \"备注说明\", \"value\": \"thing5\"}]",
                            "app_id": "bq2jof278lvdaisp29bg",
                            "created_at": "2022-07-15 10:30:48",
                            "updated_at": "2022-07-15 10:30:48",
                            "path": "{\"path\": \"pages/index/index\", \"params\": []}",
                            "remark_field": "thing5",
                            "sms_template_code": "",
                            "sms_template_variable": "",
                            "sms_type": 0
                        }
                    ]
                }
            }
        })

        // 获取数据对象分类列表
        Mock.mock(new RegExp('api/app/getObjectCategoryList'), 'post', () => {
            return {
                "Code": 0,
                "Data": null,
                "Message": "获取成功",
                "Status": 1
            }
        })
        // 获取数据对象分类分组列表
        Mock.mock(new RegExp('api/app/objectCategoryGroupList'), 'post', () => {
            return {
                "Code": 0,
                "Data": null,
                "Message": "获取成功",
                "Status": 1
            }
        })
    }
})